package com.service.wmt.impl;

import com.dao.RoomDao;
import com.dao.RoomListOVDAO;
import com.entity.Room;
import com.entity.RoomExample;
import com.entity.RoomListOV;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.wmt.RoomService;
import com.util.gzp.AjaxResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class RoomServiceImpl implements RoomService {
    @Resource
    private RoomDao roomDao;
    @Resource
    private RoomListOVDAO roomListOVDAO;

    @Override
    public Integer changeRoomStatue(Integer roomid) {
        Room room = roomDao.selectByPrimaryKey(roomid);
        room.setRoomstatusid(2);
//        roomDao.updateByPrimaryKeySelective(room);
        return roomDao.updateByPrimaryKeySelective(room);
    }

    @Override
    public Integer insertRoom(Room room) {
        return roomDao.insert(room);
    }

    @Override
    public Integer updateStatus(Integer roomid, Integer roomstatusid) {
        System.out.println("RoomServiceImpl.updateStatus"+roomstatusid);
        Room room = roomDao.selectByPrimaryKey(roomid);
        room.setRoomstatusid(roomstatusid);
        return roomDao.updateByPrimaryKeySelective(room);
    }

    @Override
    public List<Room> findAllRoom(Integer buildingid) {
        RoomExample roomExample = new RoomExample();
        RoomExample.Criteria criteria = roomExample.createCriteria();
        criteria.andBuildingidEqualTo(buildingid);
        return roomDao.selectByExample(roomExample);
    }

    @Override
    public List<RoomListOV> findOV(Integer buildingid) {
        return roomListOVDAO.findAll(buildingid);
    }

    @Override
    public Room findById(Integer roomid) {
        return roomDao.selectByPrimaryKey(roomid);
    }

    @Override
    public AjaxResponse getRoomList(Integer buildingid, Integer pageNum, Integer pageSize) {
        System.out.println("RoomServiceImpl.getRoomList: pageNum"+pageNum+"   pageSize" +pageSize+"  buildingid"+ buildingid);
        PageHelper.startPage(pageNum,pageSize);
        List<RoomListOV> listOVList = roomListOVDAO.findAll(buildingid);
        PageInfo<RoomListOV> list = new PageInfo<>(listOVList);
        System.out.println("RoomServiceImpl.getRoomList +++++++list  =");
        System.out.println("RoomServiceImpl.getRoomList  **********");
        return AjaxResponse.success(list);
    }
}
